//
//  UserDefaultsHelper.swift
//  HeadlineNews
//
//  Created by han on 2019/5/30.
//  Copyright © 2019 han. All rights reserved.
//

import UIKit

extension UserDefaults {
    
    static func set(_ object: Any, forKey defaultName: String) {
        let defaults: UserDefaults = UserDefaults.standard
        defaults.set(object, forKey: defaultName)
        defaults.synchronize()
    }
    
    static func set(_ object: Bool, forKey defaultName: String) {
        let defaults: UserDefaults = UserDefaults.standard
        defaults.set(object, forKey: defaultName)
        defaults.synchronize()
    }
    
    static func set(_ object: Int, forKey defaultName: String) {
        let defaults: UserDefaults = UserDefaults.standard
        defaults.set(object, forKey: defaultName)
        defaults.synchronize()
    }
    
    static func set(_ object: Float, forKey defaultName: String) {
        let defaults: UserDefaults = UserDefaults.standard
        defaults.set(object, forKey: defaultName)
        defaults.synchronize()
    }
    
    static func set(_ object: Double, forKey defaultName: String) {
        let defaults: UserDefaults = UserDefaults.standard
        defaults.set(object, forKey: defaultName)
        defaults.synchronize()
    }
    
    static func object(forKey key: String) -> Any! {
        let defaults: UserDefaults = UserDefaults.standard
        let value = defaults.object(forKey: key)
        defaults.synchronize()
        return value ?? "" ;
    }
    
    static func double(forKey key: String) -> Double {
        let defaults: UserDefaults = UserDefaults.standard
        let value = defaults.double(forKey: key)
        defaults.synchronize()
        return value ;
    }
    
    static func bool(forKey key: String) -> Bool {
        let defaults: UserDefaults = UserDefaults.standard
        let value = defaults.bool(forKey: key)
        defaults.synchronize()
        return value;
    }
    
    static func integer(forKey key: String) -> Int {
        let defaults: UserDefaults = UserDefaults.standard
        let value = defaults.integer(forKey: key)
        defaults.synchronize()
        return value;
    }
    
    static func float(forKey key: String) -> Float {
        let defaults: UserDefaults = UserDefaults.standard
        let value = defaults.float(forKey: key)
        defaults.synchronize()
        return value;
    }
   

}
